//
//  RefreshBaseEngine.m
//  CarCare
//
//  Created by ileo on 15/4/29.
//  Copyright (c) 2015年 baozun. All rights reserved.
//

#import "RefreshBaseEngine.h"

@interface RefreshBaseEngine()

@property (nonatomic, strong) NSTimer *refreshTimer;

@end

@implementation RefreshBaseEngine

-(NSTimer *)refreshTimer{
    
    if (!_refreshTimer) {
        __weak __typeof(self) wself = self;
        _refreshTimer = [NSTimer scheduledTimerWithTimeInterval:self.timeInterval block:^{
            if (wself.Refresh) {
                wself.Refresh();
            }
        } repeats:YES];
    }
    return _refreshTimer;
}

-(void)startRefreshWithTimeInterval:(NSTimeInterval)timeInterval{
    [self.refreshTimer setFireDate:[NSDate dateWithTimeInterval:timeInterval sinceDate:[NSDate date]]];
}

-(void)stopRefresh{
    [self.refreshTimer setFireDate:[NSDate distantFuture]];
}

@end
